import sqlite3

conn = sqlite3.connect('../database.db')
conn.row_factory = sqlite3.Row

sql = 'CREATE TABLE IF NOT EXISTS "main"."gate_pass_info_device_index" ("device" text(30), "table_index" INTEGER)'

conn.execute(sql)
conn.commit()

with open('index_result.txt', 'r', encoding='utf8') as f:
    total = 0
    for line in f:
        line_split = line.split('=')
        # if len(line_split[0]) < 5:
        #     continue
        device = line_split[0]
        index = int(line_split[1])
        sql = "insert into gate_pass_info_device_index(device, table_index) values('{}', {})".format(device, index)
        conn.execute(sql)
        total += 1
        if total % 1000 == 0:
            print('total is {}, commit'.format(total))
            conn.commit()

print('total is {}, commit'.format(total))
conn.commit()
conn.close()
